<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="formExcelTemplateAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="openDialog()">
                            {{$ti18('rxList.newBtn','新建')}}
                        </rx-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0"
                                             alias="formExcelTemplateDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                             :show-no-right="false" @click="delByIds(selectedRowKeys)">
                                    <a-icon type="delete"/>
                                    {{$ti18('rxList.delBtn','删除')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                        <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
                    </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.templateName','模板名称')">
                            <a-input
                                :placeholder="i18n('form.templateName','请输入模板名称','input')"
                                v-model="queryParam.Q_NAME__S_LK"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formExcelTemplate/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                  <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                            <span @click="openDialog(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                            <span @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                  </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import FormExcelTemplateApi from '@/api/form/core/formExcelTemplate'
import {BaseList, RxFit,Util} from "@lowcode/jpaas-common-lib";

export default {
    name: 'FormExcelTemplateList',
    mixins: [BaseList],
    components: {
        RxFit
    },
    props: {
        boDefName: {
            type: String,
            default: ""
        },
        boDefId: {
            type: String,
            default: ""
        },
        appId: {
            type: String,
            default: ""
        },
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 100,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.templateName','名称'), dataIndex: 'name', width: 100},
                {title: this.i18n('form.bodefName','业务模型名称'), dataIndex: 'boName', width: 100},
                {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ]
        }
    },
    created(){
        this.queryParam.Q_BO_ID__S_EQ=this.boDefId?this.boDefId:"";
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"excelTemplate",key);
        },
        delById(ids) {
            return FormExcelTemplateApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return FormExcelTemplateApi.query(parameter)
        },
        openDialog(record){
            let obj={
                appId:this.appId,
                boDefId:this.boDefId,
                boDefName:this.boDefName,
                templateId:record?record.id:""
            }
            let params= window.btoa(encodeURIComponent(JSON.stringify(obj)));
            let url = `/luckyExcel/edit?params=${params}`;
            window.open(url,"_blank");
        }

    }
}
</script>
<style scoped>


</style>

